package com.yitiao.data_algorithms.leetcode.editor.cn;

class CanPlaceFlowers {
    // 2023-08-01 16:28:53
    public static void main(String[] args) {
        Solution solution = new CanPlaceFlowers().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        /**
         * <h3>跳格子解法：</h3>
         * <p>如果当前是1，则下一个必不能重，直接跳</p>
         * <p>如果当前是0，则前一个也是0，不然跳不到这，如，果下一个是1，不能中，直接跳三格</p>
         */
        public boolean canPlaceFlowers(int[] flowerbed, int n) {
            for (int i = 0, len = flowerbed.length; i < len && n > 0; ) {
                if (flowerbed[i] == 1) {
                    i += 2;
                } else if (i == flowerbed.length - 1 || flowerbed[i + 1] == 0) {
                    n--;
                    i += 2;
                } else {
                    i += 3;
                }
            }
            return n <= 0;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}